Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractChildTraceEvent
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
9 / 9
10
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTrace
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTraceId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isSampled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
n/a
0 / 0
n/a
0 / 0
0
 isCompleted
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 hasErrors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getErrors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Nivseb\LaraMonitor\Struct;
4
5use Carbon\CarbonInterface;
6use Nivseb\LaraMonitor\Struct\Traits\CanGenerateId;
7
8abstract class AbstractChildTraceEvent extends AbstractTraceEvent
9{
10    use CanGenerateId;
11
12    public readonly string $id;
13    public readonly AbstractTraceEvent $parentEvent;
14    public ?bool $successful = null;
15
16    protected array $errors = [];
17
18    public function __construct(
19        AbstractTraceEvent $parentEvent,
20        public ?CarbonInterface $startAt = null,
21        public ?CarbonInterface $finishAt = null
22    ) {
23        $this->parentEvent = $parentEvent;
24        $this->id          = $this->generateId(8);
25    }
26
27    public function getId(): string
28    {
29        return $this->id;
30    }
31
32    public function getTrace(): AbstractTraceEvent
33    {
34        return $this->parentEvent->getTrace();
35    }
36
37    public function getTraceId(): string
38    {
39        return $this->parentEvent->getTraceId();
40    }
41
42    public function isSampled(): bool
43    {
44        return $this->parentEvent->isSampled();
45    }
46
47    abstract public function getName(): string;
48
49    public function isCompleted(): bool
50    {
51        return null !== $this->startAt && null !== $this->finishAt;
52    }
53
54    public function hasErrors(): bool
55    {
56        return (bool) $this->errors;
57    }
58
59    /**
60     * @return array<Error>
61     */
62    public function getErrors(): array
63    {
64        return $this->errors;
65    }
66
67    public function addError(Error $error): void
68    {
69        $this->errors[] = $error;
70    }
71}